package com.yxw.yxnet_cd_center.customer_service.controller;

import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.customer_service.dto.CprDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.CprQueryDTO;
import com.yxw.yxnet_cd_center.customer_service.service.ICprService;
import com.yxw.yxnet_cd_center.customer_service.vo.CprVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 常见问题管理Controller控制层处理
 *
 * @author xiexuxin
 * @date 2023-09-21
 */

@Slf4j
@Api(value = "常见问题库", tags = "常见问题库")
@RestController
@Validated
@RequestMapping("/v1/common-problem")
public class CprController {

    @Autowired
    private ICprService cprService;

    /**
     * 添加问题
     */
    @ApiOperation("添加问题")
    @PostMapping("/addCpr")
    public BaseResult addCpr(@RequestBody CprDTO cprDTO) {
        cprService.addCpr(cprDTO);
        return BaseResult.success();
    }

    /**
     * 删除问题
     */
    @ApiOperation("根据id删除问题")
    @PostMapping("/{problemLibId}/deleteCprById")
    public BaseResult remove(@PathVariable Long problemLibId) {
        log.info("开始处理【根据id删除问题】的请求，参数：{}", problemLibId);
        cprService.deleteCprById(problemLibId);
        return BaseResult.success();
    }

    /**
     * 批量删除问题
     */
    @ApiOperation("根据id批量删除问题")
    @PostMapping("/{problemLibIds}/batch-delete")
    public BaseResult batchDelete(@PathVariable List<Long> problemLibIds) {
        log.info("开始处理【根据id批量删除问题】的请求，参数：{}", problemLibIds);
        cprService.deleteCprByIds(problemLibIds);
        return BaseResult.success();
    }

    /**
     * 修改问题
     */
    @ApiOperation("根据id修改问题")
    @PostMapping("{problemLibId}/updateCpr")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "problemLibId", value = "问题ID", required = true, dataType = "long")
    })
    public BaseResult edit( @PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long problemLibId,
                            @RequestBody CprDTO cprDTO) {
        log.info("开始处理【根据id修改问题】的请求，ID：{}，新数据：{}", problemLibId,cprDTO);
        cprService.updateCpr(problemLibId,cprDTO);
        return BaseResult.success();
    }

    /**
     * 根据id查询问题信息
     */
    @ApiOperation(value = "根据id查询问题信息")
    @GetMapping(value = "/{problemLibId}")
    public BaseResult getInfo(@PathVariable("problemLibId") Long problemLibId) {
        log.info("开始处理【根据id查询问题信息】的请求，ID：{}", problemLibId);
        CprVO cprVO = cprService.selectCprById(problemLibId);
        return BaseResult.success(cprVO);
    }

    /**
     * 查询问题列表
     */
    @ApiOperation(value = "查询问题列表")
    @PostMapping("/cprList")
    public BaseResult<PageVO<CprVO>> cprList() {
        log.info("开始处理【查询问题列表】请求,无参数");
        PageVO<CprVO> pageVo=cprService.cprList();
        return ResultHelper.fillWithSuccess(pageVo);
    }

    /**
     * 根据问题回复查询
     */
    @ApiOperation(value = "根据问题回复查询")
    @PostMapping("/getCpr")
    public BaseResult cprList(String replyDes) {
        log.info("开始处理【查询问题列表】请求,无参数");
        List<CprVO> list = cprService.cprList(replyDes);
        return BaseResult.success(list);
    }

    /**
     *条件查询问题列表
     */
    @ApiOperation(value = "条件查询问题")
    @PostMapping(value = "/getCprList")
    public BaseResult<PageVO<CprVO>> getCprList(@RequestBody CprQueryDTO cprQueryDTO) {
        log.info("开始处理【条件查询问题】请求,参数:{}",cprQueryDTO);
        PageVO<CprVO> pageVo=cprService.getCprList(cprQueryDTO);
        return ResultHelper.fillWithSuccess(pageVo);
    }

}
